#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int n, m;
LL a[N];
int d[N];
int main()
{
	cin >> n;
	LL sum = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	LL ans1 = 0, ans2 = 0;
    LL x = sum / n;
	for (int i = 1; i <= n; i++) {
		if (a[i] < x) ans1 += (x - a[i]);
		else ans2 += (a[i] - x);
	}
	cout << min(ans1, ans2) << endl;
	return 0;
}